﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class FormThemXoaSuaChuyenXe : Form
    {
        public FormThemXoaSuaChuyenXe()
        {
            InitializeComponent();
        }

        private void txtbden_TextChanged(object sender, EventArgs e)
        {

        }

        private void FormThemXoaSuaChuyenXe_Load(object sender, EventArgs e)
        {
            List<ChuyenXeDTO> cx = BUS.ChuyenXeBUS.SelectALL();
            cbbMaChuyen.DataSource = cx;
            cbbMaChuyen.DisplayMember = "MaChuyen";
            cbbMaChuyen.ValueMember = "MaChuyen";
            cbbMaChuyen.SelectedItem = 0;
            dtpGioDi.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dtpGioDi.CustomFormat = "dd/MM/yyyy HH:mm";
            //dtpGioDi.DisplayRectangle
            dtpGioDi.RightToLeftLayout = true;
            dtpGioDen.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            dtpGioDen.CustomFormat = "dd/MM/yyyy HH:mm:ss";
            dtpGioDen.RightToLeftLayout = false;
            this.dataGridView1.DataSource = ChuyenXeBUS.SelectALL();
        }

        private void cbbMaChuyen_SelectedIndexChanged(object sender, EventArgs e)
        {
            String machuyen = cbbMaChuyen.Text;
            ChuyenXeDTO cx = ChuyenXeBUS.SelectChuyenXeByMaChuyen(machuyen);

        }

        private void btnthem_Click(object sender, EventArgs e)
        {
            String machuyen = cbbMaChuyen.Text;
            String benxedi = txtbdi.Text;
            String benxeden = txtbden.Text;
            String giodi = dtpGioDi.Value.Year.ToString() + "/" + dtpGioDi.Value.Month.ToString() + "/" + dtpGioDi.Value.Day.ToString() + " " + dtpGioDi.Value.Hour + ":" + dtpGioDi.Value.Minute + ":" + dtpGioDi.Value.Second;
            String gioden = dtpGioDen.Value.Year.ToString() + "/" + dtpGioDen.Value.Month.ToString() + "/" + dtpGioDen.Value.Day.ToString() + " " + dtpGioDen.Value.Hour + ":" + dtpGioDen.Value.Minute + ":" + dtpGioDen.Value.Second;
            try
            {
                BUS.ChuyenXeBUS.themChuyenXe(machuyen, benxedi, benxeden, giodi, gioden);
                MessageBox.Show("Insert Successfull!!");
                FormThemXoaSuaChuyenXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void cbbGioDi_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            String machuyen = cbbMaChuyen.Text;
            //else
            //{
            String benxedi = txtbdi.Text;
            String benxeden = txtbden.Text;
            String giodi = dtpGioDi.Value.Year.ToString() + "/" + dtpGioDi.Value.Month.ToString() + "/" + dtpGioDi.Value.Day.ToString() + " " + dtpGioDi.Value.Hour + ":" + dtpGioDi.Value.Minute + ":" + dtpGioDi.Value.Second;
            String gioden = dtpGioDen.Value.Year.ToString() + "/" + dtpGioDen.Value.Month.ToString() + "/" + dtpGioDen.Value.Day.ToString() + " " + dtpGioDen.Value.Hour + ":" + dtpGioDen.Value.Minute + ":" + dtpGioDen.Value.Second;
            try
            {
                BUS.ChuyenXeBUS.XoaChuyenXe(machuyen);
                MessageBox.Show("DELETE Successfull!!");
                FormThemXoaSuaChuyenXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            String machuyen = cbbMaChuyen.Text;
            //else
            //{
            String benxedi = txtbdi.Text;
            String benxeden = txtbden.Text;
            String giodi = dtpGioDi.Value.Year.ToString() + "/" + dtpGioDi.Value.Month.ToString() + "/" + dtpGioDi.Value.Day.ToString() + " " + dtpGioDi.Value.Hour + ":" + dtpGioDi.Value.Minute + ":" + dtpGioDi.Value.Second;
            String gioden = dtpGioDen.Value.Year.ToString() + "/" + dtpGioDen.Value.Month.ToString() + "/" + dtpGioDen.Value.Day.ToString() + " " + dtpGioDen.Value.Hour + ":" + dtpGioDen.Value.Minute + ":" + dtpGioDen.Value.Second;
            try
            {
                BUS.ChuyenXeBUS.SuaChuyenXe(machuyen, benxedi, benxeden, giodi, gioden);
                MessageBox.Show("Update Successfull!!");
                FormThemXoaSuaChuyenXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int i = e.RowIndex;
            cbbMaChuyen.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
            txtbdi.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
            txtbden.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
            dtpGioDi.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
            dtpGioDen.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
        }

    }
}
